import React,{Component} from 'react'
import * as pub from '../../config/public';
import {getSelectessay,submitEssSh} from '../../config/fetch'
import { Spin,message } from 'antd'
import {Link} from 'react-router'
class MyArticleDetail extends Component {
	constructor(props) {
		super(props)
		this.state={
			recordId:'',
			article:{},
            essayPhotos:[]
		}
	}
   componentWillMount() {
	   pub.loading(this,true);
		getSelectessay({essayId:this.props.params.id}).then((data) => {
              this.setState({
				article: data.essay,
				essayPhotos:data.essay.essayPhotos?data.essay.essayPhotos:[]
			  });
			  pub.loading(this,false);
		},(res)=>{
         pub.loading(this,false);
		 pub.reject(res);
		})
	}
	submitSH(){
		submitEssSh({essayId:this.props.params.id}).then((data)=>{
            if (data.result === 'RC100') {
				window.history.back();
			} else {
				message.error(data.errMsg, 3);
			}
		},(res)=>{
		 pub.reject(res);
		})
	}
	render(){
		let article=this.state.article;
		return(
		       <div className="wrapper bg-F0F4F6">
		       	<div className="layout pad-t-20">
					<Spin spinning={this.state.loading} tip="加载列表中...">   
		       		<div className="row bg-FFFFFF">
		       			<div className="article-details">
		       				<div className="title" style={{ width:'100%',textOverflow: 'ellipsis'}}>{article.essayTitle}</div>
		       				<div className="like-read-time">
		       					<span><i className="icon-heart-empty"></i>{article.sumCollection}</span>
		       					<span><i className="icon-eye-open"></i>{article.sumClick}</span>
		       					<span><i className="icon-time"></i>{pub.formatTimestamp(article.createTime)}</span>
		       				</div>
		       				<div className="line"></div>
		       				<div className="content">
								   <pre style={{width:'800px',whiteSpace:'pre-wrap',wordWrap: 'break-word'}}>{article.essayNote}</pre>
								   {
									   this.state.essayPhotos.map((item,index)=>{
										   return(
                                                <img key={index}  src={pub.getFile(item.essayPhotoPath)} alt='test' />
										   )
									   })
								   }
								   {
									   article.checkState==="5"||article.checkState==="2"?
									   <div>
										   <h3>审核意见</h3>
										   <p>{article.auditOpinion?article.auditOpinion:'无意见'}</p>
									   </div>:null
								   }
		       				</div>
		       				<div className="row text-right">
								   {
									   this.props.params.code==='collect'?
									   <Link to="/PersonalCenter/Collector/true" className="back-list">返回文章列表&gt;</Link>:
									   <a onClick={()=>{window.history.back();}} className="back-list">返回文章列表&gt;</a>
								   }
		       					
		       				</div>
							   <div className="pop-btn1">
								   {
									   article.checkState==='4'?
									   <a className="btn btn-blue" onClick={()=>this.submitSH()}>提交审核</a>:null
								   }
						       </div>
		       			</div>
		       		</div>
				  </Spin>
		       	</div>
		       </div>
			)
	}
}
export default MyArticleDetail;